/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projekt;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ADAM
 */
public class MyIterator extends AbstractIterator{
    private Data mData;
    private int mCurrent;
    private int mCounter = 1000;
    private boolean mIsDone = false;
    public MyIterator(Data pmData) {
        this.mData = pmData;
        
    }

    @Override
    public List<String> Current() {
        if(mCurrent < mData.getSize())
        {
            return mData.getData(mCurrent);
        }else
        {
            return null;
        }
    }

    @Override
    public void First() {
        mCurrent = 0;
    }

    @Override
    public boolean IsDone() {
        Mediator.getRef().update(mCounter);
        if(mCurrent >= mData.getSize() && !mIsDone)
        {
            if(mData.downloadData())
            {
                Mediator.getRef().remove(mCounter);
                Mediator.getRef().runAlgo(mData.getData(mData.getSize()-1));
                mCounter++;
                return false;
            }else
            {
                Mediator.getRef().remove(mCounter);
                mIsDone = true;
                if(mCurrent<mData.getSize())
                {
                    return false;
                }
                return mIsDone;
            }
        }else
        {
            return mIsDone;
        }
    }

    @Override
    public void Next() {
        while(!IsDone())
        {
            mCurrent++;
        }
    }   
}
